package com.abc.model;

import java.util.*;

public class ProjectYear {
	
	String year;
	
	/** mapping 'developer'&'year' to 'person effort' */
	private Map<String, PersonYearEffort> developerYearEfforts = new HashMap<String, PersonYearEffort>();
	private Map<String, PersonYearEffort> developerYearEffortsByDevName = new HashMap<String, PersonYearEffort>();
	
	
	public Map<String, PersonYearEffort> getDeveloperYearEffortsByDevName() {
		return developerYearEffortsByDevName;
	}

	public void addPersonEfforts(PersonYearEffort devYear) {
		this.year = devYear.getYear();
		developerYearEfforts.put(devYear.getId(), devYear);
		this.developerYearEffortsByDevName.put(devYear.getDeveloper(), devYear);
		
	}
	
	/**
	 * 
	 * @param developerID - compound key, see PersonYearEffort.getId()
	 */
	public List<PersonYearEffort> getDeveloperEfforts(String developerID) {
		
		//TODO not covered
		
		List<PersonYearEffort> devList = new ArrayList<PersonYearEffort>();
		for(String devName : developerYearEfforts.keySet()) {
			if(devName.equalsIgnoreCase(developerID)) {
				devList.add(developerYearEfforts.get(devName));
			}
		}
		return devList;
	}
	
	/**
	 * 
	 * @param developerID - compound key, see PersonYearEffort.getDeveloper()
	 */
	
	public List<PersonYearEffort> getDeveloperEffortsByDeveloperName(String developer) {
		
		//TODO not covered
		
		List<PersonYearEffort> devList = new ArrayList<PersonYearEffort>();
		

		
		
		for(String devName : developerYearEffortsByDevName.keySet()) {
			if(devName.equalsIgnoreCase(developer)) {
				devList.add(developerYearEffortsByDevName.get(devName));
			}
		}
		return devList;
	}
	
	
	public Collection<PersonYearEffort> getDeveloperYearEfforts() {
		return developerYearEfforts.values();
	}

	public double getTotalMonthlyEffort(int month){
		double totalEffort = 0.0;
		for (PersonYearEffort it: developerYearEfforts.values())
			totalEffort+=it.getEffort(month);
		return totalEffort;
	}
	
	public String getYear() {
		return year;
	}

}
